package snuggle.jabber.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ConfigLoader {

	private String host;
	private int port;
	private String user;
	private String pass;
	private List<String> admins;
	private String conferenceHost;
	private String conferenceRoom;
	private String conferencePass;
	private String conferenceUser;
	private int allianceID;
	private String fleetUpURL;

	private static Logger logger = Logger.getLogger(ConfigLoader.class);

	public ConfigLoader(String path) throws IOException {
		logger.info("Loading property file: " + path);

		Properties prop = new Properties();
		FileInputStream in = new FileInputStream(path);
		prop.load(in);

		host = prop.getProperty("host");
		logger.debug("Host: " + host);

		port = Integer.parseInt(prop.getProperty("port"));
		logger.debug("Post: " + port);

		user = prop.getProperty("user");
		logger.debug("User: " + user);

		pass = prop.getProperty("pass");
		logger.debug("Pass: " + pass);

		conferenceHost = prop.getProperty("conferenceHost");
		logger.debug("Conference Host: " + conferenceHost);

		conferenceRoom = prop.getProperty("conferenceRoom");
		logger.debug("Conference Room: " + conferenceRoom);

		conferencePass = prop.getProperty("conferencePass");
		logger.debug("Conference Pass: " + conferencePass);

		conferenceUser = prop.getProperty("conferenceUser");
		logger.debug("Conference User: " + conferenceUser);

		allianceID = Integer.parseInt(prop.getProperty("allianceID"));
		logger.debug("Alliance ID: " + allianceID);

		fleetUpURL = prop.getProperty("fleetUpURL");
		logger.debug("Fleet-Up URL: " + fleetUpURL);

		admins = new ArrayList<String>();
		String[] array = prop.getProperty("admins").split(",");
		for (String admin : array) {
			admins.add(admin + "@" + host);
		}
		logger.debug("Admins: " + admins);
	}

	public String getHost() {
		return host;
	}

	public int getPort() {
		return port;
	}

	public String getUser() {
		return user;
	}

	public String getPass() {
		return pass;
	}

	public List<String> getAdmins() {
		return admins;
	}

	public String getConferenceHost() {
		return conferenceHost;
	}

	public String getConferenceChat() {
		return conferenceRoom;
	}

	public String getConferencePass() {
		return conferencePass;
	}

	public String getConferenceUser() {
		return conferenceUser;
	}

	public int getAllianceID() {
		return allianceID;
	}

	public String getFleetUpURL() {
		return fleetUpURL;
	}
}
